import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

/**
 * 生成文档
 * @param app Applycation
 * @param config Object
 */
export const SwaggerInit = (app: any, config: any): void => {
  const doc = new DocumentBuilder();

  doc.setTitle(config.title);
  doc.setDescription(config.description);
  doc.setVersion(config.version);
  doc.addBearerAuth(); // 调用addBearerAuth方法添加Bearer认证信息，这意味着Swagger UI将显示一个授权按钮，允许用户输入Bearer令牌

  const configs = doc.build();

  const document = SwaggerModule.createDocument(app, configs);

  SwaggerModule.setup(config.url, app, document);
};
